package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"ustcLab/conf"
	"ustcLab/server/controller/ControllerCSV"
	"ustcLab/server/controller/ControllerDashBoard"
	"ustcLab/server/controller/ControllerGraph"
	"ustcLab/server/dao/daoimpl"
	"ustcLab/server/service/ServiceDataFresh"
)

func main() {
	fmt.Printf("[Main] Server running %s...\n", conf.Port)

	daoimpl.Ping()

	engine := gin.Default()

	gin.SetMode(gin.DebugMode)

	go ServiceDataFresh.NewHandlerRecv() //开启一个线程用来接收并处理机器传来的的数据
	v1 := engine.Group("/v1")
	{
		// 测试
		v1.GET("/print", ControllerDashBoard.HandlerPrint)
		// 读入看板数据（新）
		v1.GET("/dashboard", ControllerDashBoard.HandlerDashBoard)
		// csv文件处理
		csv := v1.Group("/csv")
		{
			csv.POST("/upload", ControllerCSV.HandlerCSVUpload)
			csv.POST("/batchUpload", ControllerCSV.HandlerBatchUpload)
		}

		// neo4j graph interfaces
		graph := v1.Group("/graph")
		{
			graph.POST("/item", ControllerGraph.HandlerItemPost)
			graph.DELETE("/item", ControllerGraph.HandlerItemDelete)
			graph.GET("/item", ControllerGraph.HandlerItemGet)
		}

		// 接收Python解析的数据
		v1.POST("/recv", ControllerDashBoard.HandlerRecv)
	}
	engine.Run(conf.Port)
}
